<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="./css/颜色选择.css">
</head>
<body>
    <div class="box">
        <div class="show"></div>
        <ul class="colorAll"></ul>
    </div>
    <script>
        window.onload = function(){
            var show = document.getElementsByClassName("show")[0];
            var colorAll = document.getElementsByClassName("colorAll")[0];
            for(var index = 0;index<18;index++){
                colorAll.innerHTML+=`<li class="item"></li>`;
            }
            var items = document.getElementsByClassName("item");
            for(var i =0;i<items.length;i++){
                var j = 0;
                var cat =[];
                while(j++<3){
                    cat.push(Math.floor(Math.random()*255));
                }
                items[i].style.backgroundColor = `rgb(${cat.join(",")})`;
                items[i].onclick = function(){
                    var color = getComputedStyle(this,null);
                    show.style.backgroundColor = color.backgroundColor;
                }
            }
        }
    </script>
</body>
</html>